import {BaseButton, BaseInput, BaseModel, BasePage, BaseRule} from "../../ts/type";
import {replace, util} from "../../ts/util";
import post from "../../axios";

export let extraConfig = (page: BasePage) => {
    replace(page, {
        operationColumnExtOperation: [
            {
                text: '生成代码',
                click: (row: any) => {
                    page.currentModel = page.models.filter(m => 'code' == m.formKey)[0]
                    page.currentModel.formInputs.filter(i => 'tableCode' == i.path)[0].defaultValue = row.tableCode
                    page.currentModel.exist = true
                    page.currentModel.formReset()
                }
            }
        ],
        models: [
            {},
            {},
            {},
            {},
            replace(new BaseModel('code', '生成代码', [
                replace(new BaseInput('表名', 'tableCode'), {
                    hidden: true,
                    span: 24,
                    inputType: 'select',
                    options: [],
                    optionsUrl: '/au/entity/tableCode/select'
                }),
                replace(new BaseInput('配置名称', 'configCode'), {
                    span: 24,
                    inputType: 'select',
                    options: [],
                    optionsUrl: '/au/config/configCode/select'
                })
            ], [
                new BaseButton('生成', () => {
                    page.currentModel.formRef?.validate((errors: any) => {
                        if (errors) {
                            util.msg?.error('请检查填写内容')
                        } else {
                            post('/entity/code', page.currentModel.model).then(() => {
                                util.msg?.success('生成成功')
                                page.currentModel.exist = false
                            })
                        }
                    })
                })
            ], page), {
                style: 'width: 50%',
                rules: {
                    configInfoId: replace(new BaseRule(), {type: 'number'})
                }
            })
        ]
    })
}